package com.mystudy.leetcode.problem.tree.p_965;

import com.mystudy.leetcode.base.TreeNode;

/**
 * @author 周志龙
 * @Email 15216876513@163.com
 * @Date on 2019/7/26 0:06
 * @Description 单值二叉树
 */
public class Solution {

    public boolean isUnivalTree(TreeNode root) {
        int ans = root.val;
        return isUnivalTree(root,ans);
    }
    private boolean  isUnivalTree(TreeNode node,int ans){
        if(node == null){
            return true;
        }

        if(node.val != ans){
            return false;
        }else{
            boolean leftBol =    isUnivalTree(node.left,ans);
            boolean rightBol = isUnivalTree(node.right,ans);
            return leftBol && rightBol;
        }

    }
}
